pub fn read()->usize {
    let mut rt = 0;
    unsafe {
        asm!("
            csrr {rt}, mstatus
        ", rt=out(reg)rt);
    }
    rt
}

pub fn set(v : usize) {
    unsafe {
        asm!("
            csrs mstatus, {v}
        ", v=in(reg)v);
    }
}

pub fn clear(v : usize) {
    unsafe {
        asm!("
            csrc mstatus, {v}
        ", v=in(reg)v);
    }
}

pub fn write(v : usize) {
    unsafe {
        asm!("
            csrw mstatus, {v}
        ", v=in(reg)v);
    }
}

pub fn spie()->usize {
    let mut rt = 0;
    unsafe {
        asm!("
            csrr {rt}, mstatus
        ", rt=out(reg)rt);
    }
    rt & (1 << 5)
}

pub fn upie()->usize {
    let mut rt = 0;
    unsafe {
        asm!("
            csrr {rt}, mstatus
        ", rt=out(reg)rt);
    }
    rt & (1 << 4)
}

pub fn mpp()->usize {
    let mut rt = 0;
    unsafe {
        asm!("
            csrr {rt}, mstatus
        ", rt=out(reg)rt);
    }
    rt & (0b11 << 11)
}
use core::arch::asm;
